package com.fnzx.service.impl;

import com.fnzx.dao.ScoreDao;
import com.fnzx.entity.ScoreEntity;
import com.fnzx.service.ScoreService;
import com.fnzx.util.PageUtils;
import com.fnzx.util.Query;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;


@Service("scoreService")
public class ScoreServiceImpl extends ServiceImpl<ScoreDao, ScoreEntity> implements ScoreService {

    @Resource
    private ScoreDao scoreDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ScoreEntity> page = this.page(
                new Query<ScoreEntity>().getPage(params),
                new QueryWrapper<ScoreEntity>()
        );
        return new PageUtils(page);
    }

    @Override
    public boolean selfJudge(Long personalId, String scoreDetails) {
        ScoreEntity scoreEntity = new ScoreEntity();
        scoreEntity.setScoredId(personalId);
        scoreEntity.setCreatedId(personalId);
        scoreEntity.setScoreDetails(scoreDetails);
        scoreEntity.setSocreSource(1000);
        return this.save(scoreEntity);
    }

    @Override
    public ScoreEntity getByScoreAndUser(Long scoredId, Long createdId) {
        ScoreEntity scoreEntity = scoreDao.getByScoreAndUser(scoredId, createdId);

        return scoreEntity;
    }

    @Override
    public boolean personalScored(Long createdId, Long personalId, String scoreDetails) {
        ScoreEntity scoreEntity = new ScoreEntity();
        scoreEntity.setScoredId(personalId);
        scoreEntity.setCreatedId(createdId);
        scoreEntity.setScoreDetails(scoreDetails);
        scoreEntity.setSocreSource(1002);
        return this.save(scoreEntity);
    }

    @Override
    public boolean enterpriseScored(Long createdId, Long enterpriseId, String scoreDetails) {
        ScoreEntity scoreEntity = new ScoreEntity();
        scoreEntity.setScoredId(enterpriseId);
        scoreEntity.setCreatedId(createdId);
        scoreEntity.setScoreDetails(scoreDetails);
        scoreEntity.setSocreSource(1003);
        return this.save(scoreEntity);
    }

    @Override
    public boolean testScored(Long personalId, Long enterpriseId, String scoreDetails) {
        ScoreEntity scoreEntity = new ScoreEntity();
        scoreEntity.setScoredId(personalId);
        scoreEntity.setCreatedId(enterpriseId);
        scoreEntity.setScoreDetails(scoreDetails);
        scoreEntity.setSocreSource(1004);
        return this.save(scoreEntity);
    }

    @Override
    public void removeByScoredId(Long projectId) {
        scoreDao.removeByScoredId(projectId);
    }


}